class Solution {
public:
    vector<vector<int>> ans;
    vector<int> stk;
    void dfs(vector<vector<int>>& graph,int depth,int maxdepth)
    {
        if(depth==maxdepth)
        {
            ans.push_back(stk);
            return;
        }
        for(auto& y:graph[depth])
        {
            stk.push_back(y);
            dfs(graph,y,maxdepth);
            stk.pop_back();
        }
        
    }
    vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
        stk.push_back(0);
        dfs(graph,0,graph.size()-1);
        return ans;
    }
};